home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0126_How to pass functions as parameters.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  648b  |  38 lines

  1. program FuncTest;
  2. {
  3.  An example of how to pass functions as parameters to
  4.  another procedure (csc).
  5.  
  6.  This program comes with no guarrentees and no support.
  7. }
  8.  
  9.                                     
  10. type
  11.   TBoolFunc = function: Boolean;
  12.   TRealFunc = function(X: Real): Real;
  13.  
  14. var
  15.   RealFunc: TRealFunc;
  16.   BoolFunc: TBoolFunc;
  17.  
  18. function Con1: Boolean; Far;
  19. begin
  20.   Con1 := True;
  21. end;
  22.  
  23. function Con2(X : Real): Real; far;
  24. begin
  25.   Con2 := X * X;
  26. end;
  27.  
  28. procedure Sambo(AFunc: TRealFunc);
  29. begin
  30.   WriteLn(AFunc(4):2:2);
  31. end;
  32.  
  33. begin
  34.   BoolFunc := Con1;
  35.   RealFunc := Con2;
  36.   WriteLn(BoolFunc);
  37.   Sambo(RealFunc);
  38. end.